// 路由配置
import {lazy, Suspense} from 'react';
import {createBrowserRouter} from "react-router-dom";
import {AuthRoute} from "@/components/AuthRoute";


// 1. 使用lazy函数引入组件 实现路由懒加载
const Layout = lazy(() => import("@/pages/Layout"));
const Home = lazy(() => import("@/pages/Home"));
const Login = lazy(() => import("@/pages/Login"));
const Publish = lazy(() => import("@/pages/Publish"));
const Article = lazy(() => import("@/pages/Article"));
const Hotpoint = lazy(() => import("@/pages/Hotpoint"));
const User = lazy(() => import("@/pages/User"));
const router = createBrowserRouter([
    {
        path: "/",
        element: <AuthRoute><Layout/></AuthRoute>,
        children: [
            {
                index: true,
                element: <Suspense fallback={"加载中..."}><Home/></Suspense>
            },
            {
                path: "/publish",
                element: <Suspense fallback={"加载中..."}><Publish/></Suspense>,
            },
            {
                path: "/article",
                element: <Suspense fallback={"加载中..."}><Article/></Suspense>,
            },
            {
                path: "/hot",
                element: <Suspense fallback={"加载中..."}><Hotpoint/></Suspense>,
            },
            {
                path: "/user",
                element: <Suspense fallback={"加载中..."}><User/></Suspense>,
            },
        ]
    },
    {
        path: "/login",
        element: <Login/>,
    },
])

export default router;